/******************************************************************************
*  Filename:       rf_patch_mce_wmbus_ctmode.h
*  Revised:        $Date: 2019-01-31 15:04:25 +0100 (to, 31 jan 2019) $
*  Revision:       $Revision: 18842 $
*
*  Description: RF core patch for CC13x0 WMBUS C- and T-Mode
*
*  Copyright (c) 2015-2019, Texas Instruments Incorporated
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions are met:
*
*  1) Redistributions of source code must retain the above copyright notice,
*     this list of conditions and the following disclaimer.
*
*  2) Redistributions in binary form must reproduce the above copyright notice,
*     this list of conditions and the following disclaimer in the documentation
*     and/or other materials provided with the distribution.
*
*  3) Neither the name of the ORGANIZATION nor the names of its contributors may
*     be used to endorse or promote products derived from this software without
*     specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
*  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
*  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/

#ifndef _RF_PATCH_MCE_WMBUS_CTMODE_H
#define _RF_PATCH_MCE_WMBUS_CTMODE_H

#include <stdint.h>
#include "../inc/hw_types.h"

#ifndef MCE_PATCH_TYPE
    #define MCE_PATCH_TYPE static const uint32_t
#endif

#ifndef PATCH_FUN_SPEC
    #define PATCH_FUN_SPEC static inline
#endif

#ifndef RFC_MCERAM_BASE
    #define RFC_MCERAM_BASE 0x21008000
#endif

#ifndef MCE_PATCH_MODE
    #define MCE_PATCH_MODE 0
#endif

MCE_PATCH_TYPE patchWmbusTmodeMce[512] =
{
    0x2fcf60b3,
    0xff803f9d,
    0x02b30666,
    0x0fff00ff,
    0x5555003f,
    0x05140510,
    0x0004002a,
    0x00310018,
    0x00610047,
    0x0092007a,
    0x00ba00a8,
    0x00d000c7,
    0x00d600d4,
    0x001f0045,
    0x00e800f8,
    0x00c000d0,
    0x008800a8,
    0x00600078,
    0x00440057,
    0x00180031,
    0x00250004,
    0x05b205a2,
    0x05d305c3,
    0x05f405e3,
    0x06140604,
    0x06350625,
    0x06560646,
    0x06770666,
    0x06980687,
    0x06b806a8,
    0x06c906b8,
    0x06e906d9,
    0x070a06fa,
    0x0016071b,
    0x001c002c,
    0x000e0034,
    0x001a0026,
    0x000d0032,
    0x00190025,
    0x000b0031,
    0x00130023,
    0x00060029,
    0x0006000e,
    0x0002000e,
    0x00040008,
    0x0006000e,
    0x0006000a,
    0x0002000c,
    0x00040008,
    0x0006000c,
    0x0006000e,
    0x0002000e,
    0x0000000e,
    0x0006000e,
    0x0006000a,
    0x0002000e,
    0x0006000a,
    0x0007000e,
    0x0007000f,
    0x0003000d,
    0x00050009,
    0x0001000d,
    0x0007000f,
    0x0001000f,
    0x0005000f,
    0x0007000f,
    0x0007000b,
    0x0003000b,
    0x0007000b,
    0x0007000b,
    0x0007000f,
    0x0003000f,
    0x0007000f,
    0x0003000f,
    0x3d1f0007,
    0x00000000,
    0x000f0400,
    0x03840000,
    0x00f4000b,
    0x80000043,
    0x06702801,
    0x091e0000,
    0x00040514,
    0x02000000,
    0x00613e10,
    0x842f0000,
    0x007f177f,
    0xaaaaaaaa,
    0x2abcaaaa,
    0x72200000,
    0xa32d7248,
    0x73057303,
    0x73047203,
    0x72047306,
    0x72767376,
    0x8001c7c0,
    0x90010001,
    0x08019010,
    0x720c9001,
    0x720e720d,
    0x7100b0c0,
    0xa0c0b0f0,
    0x81327218,
    0x39521020,
    0x00200670,
    0x11011630,
    0x6c011401,
    0x60ea60e8,
    0x61a66152,
    0x60e860e8,
    0x60e960e8,
    0x72201210,
    0x7310730f,
    0x81817311,
    0x91800010,
    0x60c8b070,
    0x60de60de,
    0xc282c931,
    0x1820c470,
    0x6e236f13,
    0x16121611,
    0x72ad68ee,
    0xc5a0c482,
    0x40fc1820,
    0x6e231203,
    0x68f91612,
    0x816060de,
    0x81409490,
    0x2a703980,
    0x16111001,
    0x84448432,
    0xc0f5c0f3,
    0x1c01c200,
    0xc1004121,
    0x41171c10,
    0x10134d19,
    0x18301803,
    0x1a101a13,
    0x69143912,
    0x13f36121,
    0x13f36121,
    0xc1001015,
    0x1a151850,
    0x39141a10,
    0xb0d8691f,
    0xb1087100,
    0xb200a0d8,
    0xb003b480,
    0xb002b013,
    0x7229b012,
    0x7100b0d0,
    0x8140b100,
    0x71009290,
    0x8140b100,
    0x453122f0,
    0x1c0313f0,
    0x9293413d,
    0x71009492,
    0x9295b100,
    0x71009494,
    0xb0d0b100,
    0x7000a480,
    0xc030a0d1,
    0xc0409760,
    0xb0f19780,
    0x7100b0c1,
    0xa0c1b0f1,
    0xa0037276,
    0x7000a002,
    0x7310730f,
    0x39818ad1,
    0x06113961,
    0x9861d030,
    0xc10067f9,
    0x64fd91c0,
    0x22e08ad0,
    0xb4834587,
    0xb0c3b0f3,
    0xc030b484,
    0xb10191c0,
    0x8ad5b0d1,
    0x416d22d5,
    0x809012f5,
    0x45822230,
    0x085081a0,
    0x1401c431,
    0xc0636f12,
    0x417a2252,
    0x617b1211,
    0x92c113f1,
    0x7100b101,
    0x1a133112,
    0x616d4576,
    0xb101a0d1,
    0x6544a0c3,
    0xb0d060de,
    0xc070b480,
    0x78c09290,
    0xb1009490,
    0xb1007100,
    0xa480a0d0,
    0xb0f3b483,
    0x7100b0c3,
    0x6544a0c3,
    0x861160de,
    0x9861d040,
    0x737667f9,
    0x72487276,
    0x72027206,
    0x73057204,
    0x60de7306,
    0x91b01230,
    0x939078b0,
    0xb0f8b32d,
    0xb016b006,
    0xb014b004,
    0xb012b002,
    0x90307810,
    0x78209050,
    0x90609040,
    0x31808140,
    0x39403980,
    0xc0f38141,
    0xc0140431,
    0x82e01441,
    0x04107831,
    0x1410c7c1,
    0x727892e0,
    0x72557276,
    0x93008ae0,
    0xc030a311,
    0xb06993b0,
    0xb0f6b064,
    0xb101a0c6,
    0xb0f1a0d1,
    0xb0f2a0c1,
    0xb486b0c2,
    0x12008441,
    0x08011a10,
    0x1012c0f0,
    0x311e0612,
    0x3911142e,
    0x789c69df,
    0xc00a67ee,
    0x1a1fc00f,
    0x1a1bc00b,
    0x9780c1b0,
    0x9760c020,
    0x789d7878,
    0xc024048d,
    0xc006c005,
    0xb0f2b205,
    0xb88d7100,
    0x46311e2a,
    0x39708af0,
    0x140b311b,
    0x1ccb8210,
    0x22204605,
    0x22204640,
    0xb7604209,
    0xa760620b,
    0x8b10b0f1,
    0x08018b21,
    0x42142271,
    0x31163315,
    0x61f7c00a,
    0x42101e3a,
    0x61f7161a,
    0x22208210,
    0xb760421d,
    0xa760621f,
    0x8b10b0f1,
    0x08018b21,
    0x422d2271,
    0x46291e0a,
    0x33163115,
    0x3115622b,
    0xc00a3116,
    0x1e3a61f7,
    0x161a422b,
    0x809061f7,
    0x42182210,
    0x22c08ad0,
    0x10b14640,
    0x08d10481,
    0x87d197c1,
    0x4e1f1c41,
    0x67f9c050,
    0x72767278,
    0xb0f1a0c1,
    0x93b0c070,
    0x3135b201,
    0x87da97c5,
    0x97c63136,
    0x189a87d9,
    0xb88995fa,
    0x31808940,
    0x16203d80,
    0x8ae83d20,
    0xc1501808,
    0x1e4185f1,
    0xc0614a5d,
    0xc00b1810,
    0x673cc00c,
    0x79ba79a9,
    0xc10010a8,
    0x85f11808,
    0x4e711e11,
    0x467a1e01,
    0x4e7a18b9,
    0x10c510b5,
    0x4a7a1ca5,
    0x1a896283,
    0x18b9108a,
    0x10b54e93,
    0x1ca518c5,
    0x62834a93,
    0x18c07a90,
    0x10c54e93,
    0xc00018b5,
    0x4a931c05,
    0xc0dc628b,
    0x671fc0d0,
    0x1ac510d5,
    0x185d120d,
    0x10cb6295,
    0xc0d0c1cc,
    0x10d5671f,
    0x185d120d,
    0xc00d6295,
    0xa4866295,
    0x67d0a5e0,
    0xc00ac00b,
    0xc007c006,
    0x8ad0c009,
    0x46a122d0,
    0x78687889,
    0x789d048e,
    0xc010048d,
    0xb7649780,
    0x9760c2b0,
    0xb0f1b0f6,
    0xb0f2b069,
    0xb88d7100,
    0x46ba1e2a,
    0x39708af0,
    0x140b311b,
    0x1ceb048b,
    0x62ca42de,
    0x22608090,
    0x221046c0,
    0x62c646d5,
    0x9760c030,
    0xb0f1b0f6,
    0x9780c1c0,
    0x46ca1cdb,
    0xb760a760,
    0x8b218b10,
    0x22710801,
    0x120a42d1,
    0x1e3a62d4,
    0x161a42cf,
    0x722062ad,
    0xb0f2c060,
    0x6ad77100,
    0x16118601,
    0x61c79601,
    0x7276b889,
    0x78c4161a,
    0xc00ec00b,
    0xb113b074,
    0x7100b0f2,
    0x1e2ab88d,
    0x8af046f7,
    0x311b3970,
    0x161e140b,
    0x470c1e6e,
    0x43581c4b,
    0xc00ec016,
    0x1066630c,
    0xc5304301,
    0x14b0089b,
    0x91916f01,
    0xc017c006,
    0x1077630c,
    0x164f430c,
    0xc007c00b,
    0x1e008150,
    0x1cf0430c,
    0x63174f0c,
    0x8b218b10,
    0x22710801,
    0xc00a4313,
    0x1e3a62e6,
    0x161a4311,
    0xa20562e6,
    0xb0f2a0c2,
    0xb0f1a0c1,
    0x67eeb113,
    0x1a106199,
    0xc0c2c001,
    0x161c6fcd,
    0x673410b3,
    0x1a101051,
    0x161c6fcd,
    0x1c156734,
    0x6b284b2f,
    0x10516332,
    0x6b281002,
    0x7000102d,
    0x4b391cd3,
    0x18d51035,
    0x10d57000,
    0x70001835,
    0x7100b0f2,
    0x8911b88e,
    0x4f441012,
    0x18211201,
    0x1c1b3131,
    0x101b4f48,
    0x10128921,
    0x12014f4d,
    0x31311821,
    0x4f511c1c,
    0xc172101c,
    0x4f561c20,
    0xb3119308,
    0x70006b3c,
    0x7276b113,
    0x9780c070,
    0x78a09760,
    0xb0f29390,
    0x80b07100,
    0x476a2230,
    0x22108090,
    0x635f4768,
    0x67f9c060,
    0x7276b073,
    0x9780c040,
    0x9760c070,
    0x8a8367ee,
    0xc0018a94,
    0x1c1f1a11,
    0xc040437a,
    0x4b7b1cf0,
    0x8940b011,
    0x3d803180,
    0x8a809550,
    0xa4888a91,
    0xc022a487,
    0x1c211801,
    0x14124f8f,
    0x63904b8d,
    0x43901c01,
    0xb4874f8f,
    0xb4886390,
    0xb041a04e,
    0xb5e0b061,
    0x80b0b113,
    0x47942230,
    0xb0f1b0c1,
    0xb0f2a0c2,
    0x7100b113,
    0xb06eb04e,
    0xc090a760,
    0x97803120,
    0x91b01300,
    0xb0f1b760,
    0x72767100,
    0xb0c6b0f6,
    0xa0c1b0f1,
    0x1a101200,
    0xc3809780,
    0xc2809760,
    0x80909760,
    0x44c82200,
    0x1e048154,
    0x978443b5,
    0x8790b0f6,
    0x1c018781,
    0x18014bcd,
    0x4bcb1ef1,
    0x1af18781,
    0x71009781,
    0x16f1b0f6,
    0xa2059781,
    0xb0f67100,
    0x6199a0c6,
    0xc2a1961d,
    0x141d16c1,
    0x101d6fd1,
    0x82e03151,
    0x14013980,
    0x83329721,
    0x06711021,
    0x06323952,
    0x16111421,
    0x43e5c1b0,
    0x97303010,
    0x6be71270,
    0x874092dd,
    0x875094a0,
    0x700094b0,
    0x1e0087e0,
    0x84a047f3,
    0x94a097e0,
    0x92d07840,
    0x94b07850,
    0x98507000,
    0x22008840,
    0xb83047fa,
    0x00007000
};

PATCH_FUN_SPEC void rf_patch_mce_wmbus_ctmode(void)
{
#ifdef __PATCH_NO_UNROLLING
    uint32_t i;

    for (i = 0; i < 512; i++)
    {
        HWREG(RFC_MCERAM_BASE + 4 * i) = patchWmbusTmodeMce[i];
    }

#else
    const uint32_t* pS = patchWmbusTmodeMce;
    volatile unsigned long* pD = &HWREG(RFC_MCERAM_BASE);
    uint32_t t1, t2, t3, t4, t5, t6, t7, t8;
    uint32_t nIterations = 64;

    do
    {
        t1 = *pS++;
        t2 = *pS++;
        t3 = *pS++;
        t4 = *pS++;
        t5 = *pS++;
        t6 = *pS++;
        t7 = *pS++;
        t8 = *pS++;
        *pD++ = t1;
        *pD++ = t2;
        *pD++ = t3;
        *pD++ = t4;
        *pD++ = t5;
        *pD++ = t6;
        *pD++ = t7;
        *pD++ = t8;
    } while (--nIterations);

#endif
}

#endif
